from PySide6.QtGui import QPainter,QPixmap
from PySide6.QtWidgets import QLineEdit
from PySide6.QtCore import Qt,Signal
from PySide6.QtGui import QFont

from core.get_url import isSteamUrl

class searchLineEdit(QLineEdit):
    parserSignal = Signal(str)
    def __init__(self,parent=None):
        super().__init__(parent)
        self.initSetup()

    def initSetup(self):
        self.setFixedSize(600,40)
        self.setFont(QFont('微软雅黑',16))

    def mouseMoveEvent(self, event):
        super().mouseMoveEvent(event)
        pos = event.pos()
        if 555 <= pos.x() <= 585 and 5 <= pos.y() <= 35:
            self.setCursor(QPixmap('./img/x.png'))
        else:
            self.setCursor(QPixmap('./img/mouse3.png'))

    def mousePressEvent(self, event):
        super().mousePressEvent(event)
        pos = event.pos()
        if 555 <= pos.x() <= 585 and 5<=pos.y()<=35:
            text = self.text().strip()
            if isSteamUrl(text):
                self.parserSignal.emit(text)

    def paintEvent(self, event):
        super().paintEvent(event)

        painter = QPainter(self)

        img = QPixmap('./img/find.png').scaled(34,34,Qt.AspectRatioMode.IgnoreAspectRatio, Qt.TransformationMode.SmoothTransformation)
        painter.drawPixmap(
            600-25-18,2, img)
